#include <iostream>
#include <memory>

template<typename T>
class MyUniquePtr {
public:
    // 构造函数
    explicit MyUniquePtr(T* ptr = nullptr) : ptr_(ptr) {}

    // 析构函数
    ~MyUniquePtr() {
        delete ptr_;
    }

    // 删除拷贝构造函数和拷贝赋值运算符
    MyUniquePtr(const MyUniquePtr&) = delete;
    MyUniquePtr& operator=(const MyUniquePtr&) = delete;

    // 移动构造函数
    MyUniquePtr(MyUniquePtr&& other) noexcept : ptr_(other.ptr_) {
        other.ptr_ = nullptr;
    }

    // 移动赋值运算符
    MyUniquePtr& operator=(MyUniquePtr&& other) noexcept {
        if (this != &other) {
            delete ptr_;
            ptr_ = other.ptr_;
            other.ptr_ = nullptr;
        }
        return *this;
    }

    // 解引用操作符
    T& operator*() const {
        return *ptr_;
    }

    T* operator->() const {
        return ptr_;
    }

    // 获取原始指针
    T* get() const {
        return ptr_;
    }

private:
    T* ptr_;
};

// 测试代码
int main() {
    MyUniquePtr<int> ptr(new int(42));
    std::cout << "Value: " << *ptr << std::endl;

    MyUniquePtr<int> ptr2 = std::move(ptr); // 使用移动语义
    // 此时 ptr 应该为 nullptr

    if (ptr.get() == nullptr) {
        std::cout << "ptr is null after move" << std::endl;
    }

    std::cout << "Value from ptr2: " << *ptr2 << std::endl;

    return 0;
}